home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!usenet
- From: clamage@Eng.Sun.COM (Steve Clamage)
- Newsgroups: comp.std.c
- Subject: Re: Paradox due to A7.1 Pointer generation rul
- Date: 19 Mar 1996 00:12:46 GMT
- Organization: Sun Microsystems Inc.
- Message-ID: <4iku5u$btv@engnews1.Eng.Sun.COM>
- References: <4ikp70$mkf@franklin.its.utas.edu.au>
- Reply-To: clamage@Eng.Sun.COM
- NNTP-Posting-Host: taumet.eng.sun.com
-
- In article mkf@franklin.its.utas.edu.au, vmm@tasman.its.utas.edu.au (Vishv Malhotra) writes:
- >
- >In the following function a++; is acceptable but b++; is not.
- >
- > void foo(int a[20]) {
- > int b[20];
- >
- > a++;
- > b++;
- > }
- >
- >I understand the reason, but I wish to know if there is any thought
- >on elimination the anomaly?
-
- You can modify 'a' because its declaration is implicitly rewritten by the
- compiler to "int *a". That is, even though its declaration looks like an
- array, "a" is really a pointer variable.
-
- You cannot modify 'b' because it is the name of an array, and represents
- its address. For example, the following is disallowed for the same reason:
- int x;
- (&x)++; /* error */
-
- How would you go about either forbidding a++ or allowing b++, without
- also making fundamental changes throughout the language?
-
- Personally, I think the array/pointer schizophrenia in C was a mistake, as
- it leads to endless confusion and prevents using arrays as first-class
- objects. But changing the current relationship of pointers and arrays in C
- would break all existing C programs, since even the declaration of main
- relies on it.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
-
-
-